# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:find_records_with_numbers1_0.py
@Time:2024/12/10 16:54

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

import os
import pandas as pd
import re

def find_records_with_numbers(directory):
    # 存储符合条件的记录
    records_with_numbers = []

    # 遍历指定目录下的所有文件
    for filename in os.listdir(directory):
        if filename.endswith('.csv'):
            file_path = os.path.join(directory, filename)
            # 读取CSV文件
            try:
                df = pd.read_csv(file_path)
                # 检查标题列中是否包含数字
                df['contains_number'] = df['标题'].apply(lambda x: bool(re.search(r'\d', str(x))))
                # 筛选出包含数字的记录
                number_records = df[df['contains_number']].to_dict('records')
                # 排除标题中包含“新闻联播”的记录
                filtered_records = [record for record in number_records if '新闻联播' not in record['标题']]
                records_with_numbers.extend(filtered_records)
            except Exception as e:
                print(f"Error reading {filename}: {e}")

    return records_with_numbers

if __name__ == "__main__":
    # 使用示例
    directory = '../news/'  # 替换为你的目录路径
    results = find_records_with_numbers(directory)
    for result in results:
        print(result)